package com.gogowan.agroenterprise.newview;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RadioButton;

import com.gogowan.agroenterprise.R;
import com.gogowan.agroenterprise.base.BaseActivity;
import com.gogowan.agroenterprise.model.LoginResultInfo;
import com.gogowan.agroenterprise.utils.Utils;

import java.util.ArrayList;
import java.util.List;

public class New_DH_LIst_Activity extends FragmentActivity {
    private FragmentPagerAdapter fragmentPagerAdapter;
    private List<Fragment> fragments=new ArrayList<>();
    private ListFragment listFragment1,listFragment2;
    private ViewPager viewPager;
    private RadioButton rb1,rb2;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_dh_list);
        listFragment1=new ListFragment();
        listFragment2=new ListFragment();
        listFragment1.setType(0);
        listFragment2.setType(1);
        fragments.add(listFragment1);
        fragments.add(listFragment2);
        rb1=(RadioButton)findViewById(R.id.not_list);
        rb2=(RadioButton)findViewById(R.id.ok_list);
        fragmentPagerAdapter=new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        };
        viewPager=(ViewPager)findViewById(R.id.dh_list_vp);
        findViewById(R.id.goods_allocation_add_fh_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        viewPager.setAdapter(fragmentPagerAdapter);
//        listFragment1.InitHttp(loginResultInfo,this);
//        listFragment2.InitHttp(loginResultInfo,this);
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position){
                    case 0:
                        rb1.setChecked(true);
                        rb2.setChecked(false);
                        break;
                    case 1:
                        rb1.setChecked(false);
                        rb2.setChecked(true);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        rb1.performClick();
        rb1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewPager.setCurrentItem(0);
            }
        });
        rb2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewPager.setCurrentItem(1);
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode==206){
            listFragment1.InitHttp();
            listFragment2.InitHttp();
        }
    }
}
